#不能命名为email.py，与库冲突了

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def send_email(sender_email, sender_password, recipient_email, subject, message):
    # 设置邮件内容
    msg = MIMEMultipart()
    msg['From'] = sender_email
    msg['To'] = recipient_email
    msg['Subject'] = subject

    # 添加邮件正文
    msg.attach(MIMEText(message, 'plain'))

    # 连接 SMTP 服务器
    server = smtplib.SMTP_SSL('smtp.qq.com', 465)  # 使用 SSL 连接 QQ 邮箱的 SMTP 服务器

    # 登录邮箱账号
    server.login(sender_email, sender_password)

    # 发送邮件
    server.send_message(msg)

    # 关闭连接
    server.quit()

# 使用示例
sender_email = '2955992336@qq.com'  # 发件人邮箱地址
sender_password = 'dtqrgjuvctwvdcfj'  # QQ 邮箱授权码，不是登录密码
recipient_email = '2076925659@qq.com'  # 收件人邮箱地址
subject = 'Test Email'  # 邮件主题
message = 'This is a test email sent from Python.'  # 邮件内容

send_email(sender_email, sender_password, recipient_email, subject, message)
